<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\kuaishouesp;

use app\enum\KuaiShouEspUrlEnum;
use app\service\BaseService;
use proxy\Client;

class AdvertiserService extends BaseService
{
    /**
     * 刷新token.
     * @param array $headers 头部
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function refreshToken(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = KuaiShouEspUrlEnum::getServiceName('advertiser');
            $serviceUrl = KuaiShouEspUrlEnum::getServiceUrl('advertiser', 'refresh_token');
            return $client->postJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }


    /**
     * 获取账户信息.
     * @param array $headers 头部
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAccountInfo(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = KuaiShouEspUrlEnum::getServiceName('advertiser');
            $serviceUrl = KuaiShouEspUrlEnum::getServiceUrl('advertiser', 'advertiser_info');
            return $client->postJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

}
